using System;
using System.IO;
using System.Text;

namespace Hotel.UI.Common
{
	/// <summary>
	/// 文本日志记录辅助类
	/// </summary>
	public class LogTextHelper
	{
		private static string string_0;

		public static bool InfoLevel;

		public static bool DebugLevel;

		static LogTextHelper()
		{
			
			LogTextHelper.string_0 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log");
			LogTextHelper.InfoLevel = true;
			LogTextHelper.DebugLevel = false;
			if (!Directory.Exists(LogTextHelper.string_0))
			{
				Directory.CreateDirectory(LogTextHelper.string_0);
			}
		}

		public LogTextHelper()
		{
			
			
		}

		/// <summary>
		/// 记录信息
		/// </summary>
		/// <param name="ex">错误信息</param>
		public static void Debug(object ex)
		{
			LogTextHelper.WriteLine(ex.ToString());
		}

		/// <summary>
		/// 记录信息和异常信息
		/// </summary>
		/// <param name="message">错误信息</param>
		/// <param name="ex">异常对象</param>
		public static void Debug(object message, Exception ex)
		{
			LogTextHelper.WriteLine(message.ToString(), ex);
		}

		/// <summary>
		/// 记录信息
		/// </summary>
		/// <param name="ex">错误信息</param>
		public static void Error(object ex)
		{
			LogTextHelper.WriteLine(ex.ToString());
		}

		/// <summary>
		/// 记录信息和异常信息
		/// </summary>
		/// <param name="message">错误信息</param>
		/// <param name="ex">异常对象</param>
		public static void Error(object message, Exception ex)
		{
			LogTextHelper.WriteLine(message.ToString(), ex);
		}

		/// <summary>
		/// 记录信息
		/// </summary>
		/// <param name="ex">错误信息</param>
		public static void Info(object ex)
		{
			LogTextHelper.WriteLine(ex.ToString());
		}

		/// <summary>
		/// 记录信息和异常信息
		/// </summary>
		/// <param name="message">错误信息</param>
		/// <param name="ex">异常对象</param>
		public static void Info(object message, Exception ex)
		{
			LogTextHelper.WriteLine(message.ToString(), ex);
		}

		/// <summary>
		/// 记录信息
		/// </summary>
		/// <param name="ex">错误信息</param>  
		public static void Warn(object ex)
		{
			LogTextHelper.WriteLine(ex.ToString());
		}

		/// <summary>
		/// 记录信息和异常信息
		/// </summary>
		/// <param name="message">错误信息</param>
		/// <param name="ex">异常对象</param>
		public static void Warn(object message, Exception ex)
		{
			LogTextHelper.WriteLine(message.ToString(), ex);
		}

		/// <summary>
		/// 记录信息
		/// </summary>
		/// <param name="message">错误信息</param>
		public static void WriteLine(string message)
		{
			DateTime now = DateTime.Now;
			string str = string.Concat(now.ToString("[yyyy-MM-dd HH:mm:ss]    "), message, "\r\n");
			now = DateTime.Now;
			string str1 = string.Concat(now.ToString("yyyyMMdd"), ".log");
			try
			{
				if (LogTextHelper.InfoLevel)
				{
					File.AppendAllText(Path.Combine(LogTextHelper.string_0, str1), str, Encoding.UTF8);
				}
				if (LogTextHelper.DebugLevel)
				{
					Console.WriteLine(str);
				}
			}
			catch
			{
			}
		}

		/// <summary>
		/// 记录信息
		/// </summary>
		/// <param name="message">错误信息</param>
		/// <param name="ex">异常信息</param>
		public static void WriteLine(string message, Exception ex)
		{
			string[] str = new string[5];
			DateTime now = DateTime.Now;
			str[0] = now.ToString("[yyyy-MM-dd HH:mm:ss]    ");
			str[1] = message;
			str[2] = "\r\n";
			str[3] = ex.ToString();
			str[4] = "\r\n";
			string str1 = string.Concat(str);
			now = DateTime.Now;
			string str2 = string.Concat(now.ToString("yyyyMMdd"), ".log");
			try
			{
				if (LogTextHelper.InfoLevel)
				{
					File.AppendAllText(Path.Combine(LogTextHelper.string_0, str2), str1, Encoding.UTF8);
				}
				if (LogTextHelper.DebugLevel)
				{
					Console.WriteLine(str1);
				}
			}
			catch
			{
			}
		}

		/// <summary>
		/// 记录类名、消息等信息到日志文件
		/// </summary>
		/// <param name="className">类名</param>
		/// <param name="funName">全名</param>
		/// <param name="message">错误信息</param>
		public static void WriteLine(string className, string funName, string message)
		{
			LogTextHelper.WriteLine(string.Format("{0}：{1}\r\n{2}", className, funName, message));
		}
	}
}